﻿<navControls:Page x:Class="ExpenseReport.ExpenseReportSummary" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	mc:Ignorable="d" d:DesignWidth="899" d:DesignHeight="284" 
    xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:form="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm"
    xmlns:nav="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
    xmlns:navControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:ria="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"  
    xmlns:srt="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls"  
    xmlns:windata="clr-namespace:System.Windows.Data;assembly=System.ComponentModel"
    xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows"
    xmlns:localprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:er="clr-namespace:ExpenseReport"
    Width="Auto"
    Height="Auto"
    Title="ExpenseReportSummary Page">
   <StackPanel x:Name="LayoutRoot" Margin="8,8,0,4" HorizontalAlignment="Stretch">
        <StackPanel.Resources>
            <er:EnumConverter x:Key="EnumConverter" />
            
            <ria:DomainDataSource x:Name="ddsYourExpenseReports"
                         LoadMethodName="LoadExpenseReportsForUser"
                         PageSize="30"
                         AutoLoad="False"
                         >
                <ria:DomainDataSource.SortDescriptors>
                    <srt:SortDescriptor PropertyPath="Company" Direction="Ascending"/>
                </ria:DomainDataSource.SortDescriptors>
                <ria:DomainDataSource.GroupDescriptors>
                    <srt:GroupDescriptor PropertyPath="Status" />
                </ria:DomainDataSource.GroupDescriptors>
                <ria:DomainDataSource.DomainContext>
                    <er:ExpenseData/>
                </ria:DomainDataSource.DomainContext>
            </ria:DomainDataSource>
            <ria:DomainDataSource x:Name="ddsApprovalExpenseReports"
                         LoadMethodName="LoadExpenseReportsForApproval"
                         PageSize="4"
                         AutoLoad="False"
                         >
                <ria:DomainDataSource.SortDescriptors>
                    <srt:SortDescriptor PropertyPath="Company" Direction="Ascending"/>
                </ria:DomainDataSource.SortDescriptors>
                <ria:DomainDataSource.DomainContext>
                    <er:ExpenseData/>
                </ria:DomainDataSource.DomainContext>
            </ria:DomainDataSource>
        </StackPanel.Resources>
        <StackPanel x:Name="yourExpenseReportPanel" Visibility="Collapsed">
            <TextBlock Margin="8,8,0,4" Text="Your Expense Reports" TextWrapping="Wrap" FontSize="12" FontWeight="Bold" FontFamily="Portable User Interface" FontStyle="Italic"/>
            <data:DataGrid x:Name="dgYourExpenseReport" Margin="0,4,0,0"
                           Width ="500" Height="276"
                           AutoGenerateColumns="False"
                           IsReadOnly="True"
                           ItemsSource="{Binding Mode=TwoWay, Source={StaticResource ddsYourExpenseReports}, Path=Data}"
                           >
                <!--This header style is required to handle grouping on the Report Status and include the correct group
                name in the group header.-->
                <data:DataGrid.RowGroupHeaderStyles>
                    <Style TargetType="data:DataGridRowGroupHeader">
                        <Setter Property="Cursor" Value="Arrow" />
                        <Setter Property="IsTabStop" Value="False" />
                        <Setter Property="Background" Value="#FFE4E8EA" />
                        <Setter Property="Height" Value="20"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="data:DataGridRowGroupHeader">
                                    <localprimitives:DataGridFrozenGrid Name="Root" Background="{TemplateBinding Background}">
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CurrentStates">
                                                <vsm:VisualState x:Name="Regular"/>
                                                <vsm:VisualState x:Name="Current">
                                                    <Storyboard>
                                                        <DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <localprimitives:DataGridFrozenGrid.Resources>
                                            <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
                                                <Grid Background="Transparent">
                                                    <vsm:VisualStateManager.VisualStateGroups>
                                                        <vsm:VisualStateGroup x:Name="CommonStates">
                                                            <vsm:VisualState x:Name="Normal"/>
                                                            <vsm:VisualState x:Name="MouseOver">
                                                                <Storyboard>
                                                                    <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" Duration="0" To="#FF6DBDD1"/>
                                                                    <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/>
                                                                </Storyboard>
                                                            </vsm:VisualState>
                                                            <vsm:VisualState x:Name="Pressed">
                                                                <Storyboard>
                                                                    <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" Duration="0" To="#FF6DBDD1"/>
                                                                    <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/>
                                                                </Storyboard>
                                                            </vsm:VisualState>
                                                            <vsm:VisualState x:Name="Disabled">
                                                                <Storyboard>
                                                                    <DoubleAnimation Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Opacity" To=".5"/>
                                                                    <DoubleAnimation Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Opacity" To=".5"/>
                                                                </Storyboard>
                                                            </vsm:VisualState>
                                                        </vsm:VisualStateGroup>
                                                        <vsm:VisualStateGroup x:Name="CheckStates">
                                                            <vsm:VisualState x:Name="Checked" />
                                                            <vsm:VisualState x:Name="Unchecked">
                                                                <Storyboard>
                                                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Visibility">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Visibility">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </vsm:VisualState>
                                                        </vsm:VisualStateGroup>
                                                    </vsm:VisualStateManager.VisualStateGroups>

                                                    <Path Stretch="Uniform" Data="F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z" Width="5" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="CollapsedArrow" Visibility="Collapsed" Stroke="#FF414345"/>
                                                    <Path Stretch="Uniform" Data="F1 M 0,1 L 1,1 L 1,0 L 0,1 Z" Width="6" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="ExpandedArrow" Fill="#FF414345"/>
                                                </Grid>
                                            </ControlTemplate>
                                        </localprimitives:DataGridFrozenGrid.Resources>

                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>

                                        <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFFFFFFF" Height="1"/>
                                        <Rectangle Grid.Column="1" Grid.Row="1" Name="IndentSpacer" />
                                        <ToggleButton Grid.Column="2" Grid.Row="1" Name="ExpanderButton" Height="15" Width="15" Template="{StaticResource ToggleButtonTemplate}" Margin="2,0,0,0"/>

                                        <StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,0,1">
                                            <TextBlock x:Name="PropertyNameElement" Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}"/>
                                            <!--The change that was needed to use a converter to display correct group name.-->
                                            <TextBlock Margin="4,0,0,0" Text="{Binding Name, Converter={StaticResource EnumConverter}}" />
                                            <TextBlock x:Name="ItemCountElement" Margin="4,0,0,0" Visibility="{TemplateBinding ItemCountVisibility}"/>
                                        </StackPanel>

                                        <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFD3D3D3" Height="1" Grid.Row="2"/>
                                        <Rectangle Name="FocusVisual" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="3" Stroke="#FF6DBDD1" StrokeThickness="1" HorizontalAlignment="Stretch" 
                                            VerticalAlignment="Stretch" IsHitTestVisible="false" Opacity="0" />
                                        <localprimitives:DataGridRowHeader Name="RowHeader" Grid.RowSpan="3" localprimitives:DataGridFrozenGrid.IsFrozen="True"/>

                                    </localprimitives:DataGridFrozenGrid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                </data:DataGrid.RowGroupHeaderStyles>
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Binding="{Binding Company}" Header="Company"/>
                    <data:DataGridTextColumn Binding="{Binding Department}" Header="Department"/>
                    <data:DataGridTextColumn Binding="{Binding Description}" Header="Description"/>
                    <data:DataGridTextColumn Binding="{Binding Status, Converter={StaticResource EnumConverter}}" Header="Status" SortMemberPath="Status" IsReadOnly="True"/>
                </data:DataGrid.Columns>
            </data:DataGrid>
            <form:DataPager PageSize="30" Margin="0,-2,0,0" Source="{Binding Mode=TwoWay, Source={StaticResource ddsYourExpenseReports}, Path=Data}"/>
            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="4">
                <Button Width="90"  Content="Edit" Margin="4,0,4,0" Click="EditButton_Click"/>
                <Button Width="90" Content="Create" Margin="4,0,4,0" Click="CreateButton_Click"/>
                <Button Width="90" Content="Submit" Margin="4,0,4,0" Click="SubmitButton_Click"/>
            </StackPanel>
        </StackPanel>
        <StackPanel x:Name="approvalExpenseReportPanel" Visibility="Collapsed">
            <TextBlock Margin="8,30,0,4" Text="Expense Reports for Approval" TextWrapping="Wrap" FontSize="12" FontWeight="Bold" FontFamily="Portable User Interface" FontStyle="Italic"/>
            <data:DataGrid x:Name="dgApprovalExpenseReport" Margin="0,4,0,0"
                           Width ="500"
                           AutoGenerateColumns="False"
                           ItemsSource="{Binding Mode=TwoWay, Source={StaticResource ddsApprovalExpenseReports}, Path=Data}"
                           GridLinesVisibility="All"
                           IsReadOnly="True"
                           >
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Binding="{Binding Path=Employee.Name}" Header="Employee"/>
                    <data:DataGridTextColumn Binding="{Binding Company}" Header="Company"/>
                    <data:DataGridTextColumn Binding="{Binding Department}" Header="Department"/>
                    <data:DataGridTextColumn Binding="{Binding Description}" Header="Description"/>
                    <data:DataGridTextColumn Binding="{Binding RptStatus}" Header="Status" SortMemberPath="Status"/>
                </data:DataGrid.Columns>
            </data:DataGrid>
            <form:DataPager PageSize="4" Margin="0,-4,0,0" Source="{Binding Mode=TwoWay, Source={StaticResource ddsApprovalExpenseReports}, Path=Data}"/>
            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="4">
                <Button Width="90"  Content="Approve" Margin="4,0,4,0" Click="ApproveButton_Click"/>
                <Button Width="90" Content="Reject" Margin="4,0,4,0" Click="RejectButton_Click"/>
            </StackPanel>
        </StackPanel>
    </StackPanel>
</navControls:Page>
